import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:news_flutter/models/circle_rec_model.dart';
import 'package:news_flutter/utils/http_request_util.dart';
import 'package:news_flutter/utils/precompile.dart';
import 'package:news_flutter/widgets/custom/cache_image_widget.dart';
import 'package:news_flutter/widgets/custom/my_diver_widget.dart';
import 'package:news_flutter/widgets/custom/refresh_tableview_widget.dart';
import 'package:news_flutter/extension/num_ext.dart';

class CircleRecPage extends StatefulWidget {
  @override
  _CircleRecPageState createState() => _CircleRecPageState();
}

class _CircleRecPageState extends State<CircleRecPage> {
  List<CircleArticleModel> _list =[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _loadData();
  }
  @override
  Widget build(BuildContext context) {
    return RefreshTableView(
      itemBuilder: (context,int index){
        CircleArticleModel model = _list[index];
        return _cell(model);
      },
      itemCount: _list.length,
      onRefresh: (){
        _loadData();
      },
    );
  }
  Widget _cell(CircleArticleModel model){
    return Column(
      children: <Widget>[
        //分割线
        MyDiver(height: 5.0,color: MyColor.LISTVIEW_BG,),
        //头像、圈子名称
        Row(
          children: <Widget>[
            //头像
            Container(
              margin: EdgeInsets.symmetric(horizontal: 10,vertical: 5),
              width: 34,height: 34,
              child: MyCacheImage(url: model.circle_img,radius: 10,),
            ),
            Expanded(
              child: Text(model.circle_name,style: TextStyle(color: MyColor.TEXT_BLACK,fontSize: 15,fontWeight: FontWeight.bold),),
            ),
          ],
        ),
        //内容
        InkWell(
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 10,vertical: 5),
            alignment: Alignment.topLeft,
            child: Text(model.content,style: TextStyle(fontSize: 14,color: MyColor.TEXT_GRAY),maxLines: 4,textAlign: TextAlign.left,overflow: TextOverflow.ellipsis,),
          ),
          onTap: (){},
        ),
        //作者
        Row(
          children: <Widget>[
            //头像
            Container(
              margin: EdgeInsets.only(left: 10,right: 5,top: 5,bottom: 5),
              width: 24,height: 24,
              child: MyCacheImage(url: model.author_img,radius: 10,),
            ),
            Expanded(
              child: Text(model.author_name,style: TextStyle(color: MyColor.TEXT_BLACK,fontSize: 14),),
            ),
          ],
        ),
        //点赞、评论、分享
        Container(
          padding: EdgeInsets.symmetric(horizontal: 20,vertical: 5),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              _cellFootNumnWidget(Icons.thumb_up, "${model.thumb_count.friendlyNumWanDes()}"),
              _cellFootNumnWidget(Icons.message, "${model.comment_count.friendlyNumWanDes()}"),
              _cellFootNumnWidget(Icons.share, "分享"),
            ],
          ),
        ),
      ],
    );
  }
  //sub widget
  Widget _cellFootNumnWidget(IconData icon,String count){
    return InkWell(
      onTap: (){},
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 10,vertical: 5),
        child: Row(
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(right: 5),
              child: Icon(icon,color: MyColor.TEXT_GRAY,size: 16,),
            ),
            Text(count,style: TextStyle(color: MyColor.TEXT_GRAY,fontSize: 14),)
          ],
        ),
      ),
    );
  }
  void _loadData(){
    HttpRequestUtil().get("txapi/tiangou/index", param: {}).then((value) {
//      List newslist = value["newslist"];
    /*
  String content;
  String circle_img;
	String circle_name;
	String author_name;
	String author_img;
	int thumb_count;
	int comment_count;
    * */
    List newslist = [
      {
        "circle_img":"https://tvax2.sinaimg.cn/crop.0.15.750.750.1024/6a1f75efly8fl9zj849ggj20ku0lowfp.jpg?KID=imgbed,tva&Expires=1608268004&ssig=5xtBa5Cj7A",
        "circle_name":"婴幼儿童圈",
        "content":"时代真变了。现在都是多个大人围一个孩子转，我们小时候是多个小孩围着一个大人转[允悲]//@剑音长水修螺_阿绿阿黄:猜测家里如果只有一个人拒绝，其他大人哄着，这娃的毛病还是不太好改。话说现在的小孩子的眼力见真的可以的，会主动逗外人笑，外人如果不回笑，娃们表情就变了。。。",
        "author_name":"奶舅_吴斌",
        "author_img":"https://tvax4.sinaimg.cn/crop.0.17.132.132.1024/624f0da1ly1g4ps3uyk0gj203o04n74s.jpg?KID=imgbed,tva&Expires=1608526667&ssig=vqmQ1sOink",
        "thumb_count":4483,
        "comment_count":493,
      },
      {
        "circle_img":"https://wx2.sinaimg.cn/large/001NUlVxly1glv8m91nchj608w08w3yt02.jpg",
        "circle_name":"#劳荣枝案开庭#",
        "content":"【#劳荣枝案开庭#，其家属及受害人家属进入庭审现场】12月21日，江西南昌。劳荣枝案9时开庭，大量市民来到南昌中院门口排队等待进入旁听。劳荣枝家属及受害人小木匠陆中明的妻子于8时许通过法院安检进入厅内。°劳荣枝案开庭，其家属及受害人家属进入庭审现场 L澎湃新闻的微博视频 ​​​ ​​​​",
        "author_name":"Vista看天下",
        "author_img":"https://tvax1.sinaimg.cn/crop.0.0.750.750.1024/4ee36f05ly8gdi6nnopsqj20ku0ku0u3.jpg?KID=imgbed,tva&Expires=1608526667&ssig=w6iez0OtUG",
        "thumb_count":2342,
        "comment_count":2142,
      },
      {
        "circle_img":"https://wx1.sinaimg.cn/large/002c6guQly1gludn6q287j608c08cdgg02.jpg",
        "circle_name":"#如何看待两头婚#",
        "content":"两头婚既不属于男娶女嫁，也不属于女招男入赘，小夫妻成家后依旧与双方原生家庭保持一定“黏性”，通常各住各家。他们一般会生育两个小孩，第一个随父姓，由男方抚养为主，第二个随母姓，由女方抚养为主。在两头婚家庭里，没有外公外婆的概念，小孩对爸爸妈妈的父母都叫爷爷奶奶。​​​​",
        "author_name":"齐鲁晚报 ",
        "author_img":"https://tvax3.sinaimg.cn/crop.0.0.591.591.50/002c6guQly8gln2ceoea7j60gf0gfgnf02.jpg?KID=imgbed,tva&Expires=1608528102&ssig=JgZ6lPuJ6o",
        "thumb_count":80817000,
        "comment_count":2947,
      },
      {
        "circle_img":"https://wx2.sinaimg.cn/large/0034c2ttly1glt2qu0e87j60830830sz02.jpg",
        "circle_name":"#如何应对被社会性死亡#",
        "content":"【#如何应对被社会性死亡# ？[思考]】一条朋友圈、一段监控视频，让一个人变成网络暴力受害者，这种当众出丑被人们形容为“社会性死亡”，意思是羞到想要立刻去世。“社会性死亡”展示了网络谣言和网络暴力的残酷性。面对这种严重后果，我们应该怎么做呢？ L新华网的微博视频 ​​​​​",
        "author_name":"新华网 ",
        "author_img":"https://tvax4.sinaimg.cn/crop.36.48.945.945.50/a782e4ably8ghkf93ix89j20u00u00ur.jpg?KID=imgbed,tva&Expires=1608528277&ssig=Gzm93Kko1r",
        "thumb_count":230000000,
        "comment_count":7035,
      },
    ];
      List<CircleArticleModel> list = newslist.map((e) => CircleArticleModel.fromJsonMap(e)).toList();
      setState(() {
        _list = list;
      });
    });
  }
}
